package com.javaear.beangenerator;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;

/**
 * current just provide mysql config
 *
 * @author aooer
 */
class Configure {

    private Context context;

    public Context getContext() {
        return context;
    }

    /***************
     * singleton
     ****************/

    private static class ConfigureHolder {
        private static Configure INSTANCE = new Configure();
    }

    public static Configure getInstance() {
        return ConfigureHolder.INSTANCE;
    }

    private Configure() {
        try {
            if (this.context != null) return;
            InputStream inputStream;
            ClassLoader cl;
            if ((cl = Configure.class.getClassLoader()) != null)
                inputStream = cl.getResourceAsStream("beanGenerator.properties");
            else
                inputStream = ClassLoader.getSystemResourceAsStream("beanGenerator.properties");
            Properties config = new Properties();
            config.load(inputStream);
            inputStream.close();
            this.context = new Context();
            for (Map.Entry<Object, Object> entry : config.entrySet())
                this.context.put(entry.getKey().toString(), entry.getValue().toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
